package boot3.mapper;

import boot3.pojo.Message;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessageMapper {
    //获取当前的所有需要发送的消息
    @Select("select * from message")
    public List<Message> getAllMessage();
    //插入一条未发送的消息
    @Insert("insert message value(#{message_id},#{sender_id},#{send_time},#{receiver_id},#{content},#{system}," +
            "#{watch},#{sender_name},#{receiver_name},#{online})")
    public Boolean setMessage(Message message);
    //根据消息ID删除一条消息
    @Delete("delete from message where message_id=#{message_id}")
    public Boolean deleteMessage(String message_id);
    //根据接受者ID获取消息列表
    @Select("select * from message where receiver_id=#{receiver_id} or sender_id=#{receiver_id}")
    public List<Message> getMessageByReceiverId(String receiver_id);
    //根据message_id修改消息的阅读状态
    @Update("update message set watch=true where message_id=#{message_id}")
    public Boolean updateMessageWatch(String message_id);
    //根据发送者姓名和接受者姓名更新消息中的阅读状态
    @Update("update message set watch=true where receiver_name=#{receiver_name} and sender_name=#{sender_name}")
    public Boolean updateMessageWatchByRS(String receiver_name, String sender_name);
}

